<template>
  <el-card class="app-container">
    <c-u-r-d-table :option="option"/>
  </el-card>
</template>

<script>

import ColumnType from '@/framework/constant/ColumnType'
import OnlineStatusEnum from '@/framework/constant/OnlineStatusEnum'
import {adminApi} from '@/feature/mgr/infra/api/adminApi'
import CURDTable from '@/framework/components/table/CURDTable'
import {roleApi} from "@/feature/mgr/infra/api/roleApi";
import AccountStatusEnum from "@/framework/constant/AccountStatusEnum";
import AdminTypeEnum from "@/feature/mgr/infra/constants/AdminTypeEnum";
import {storeApi} from "@/feature/mct/infra/api/storeApi";

export default {
  components: {CURDTable},
  data() {
    return {
      option: {
        dialogWidth: '600px',
        requestApi: adminApi,
        showSelection: false,
        columns: [
          {
            label: '登录账号',
            searchable: true,
            required: true,
            span: 24,
            width: 120,
            prop: 'username'
          },
          {
            label: '姓名',
            span: 24,
            searchable: true,
            width: 120,
            required: true,
            prop: 'title'
          },
          {
            label: '角色',
            span: 24,
            hiddenInForm: true,
            width: 'auto',
            required: true,
            prop: 'roleNameList'
          }, {
            label: '角色',
            span: 24,
            searchable: true,
            hiddenInTable: true,
            type: ColumnType.SELECT,
            options: roleApi.listAll(),
            required: true,
            renderOptions: {multiple: true},
            prop: 'roleIdList'
          },
          {
            label: '上次登录IP',
            hiddenInForm: true,
            prop: 'lastLoginIp'
          },
          {
            label: '上次登录时间',
            hiddenInForm: true,
            prop: 'lastLoginTime'
          },
          {
            label: '状态',
            searchable: true,
            width: 80,
            type: ColumnType.RADIO,
            hiddenInForm: true,
            options: AccountStatusEnum,
            prop: 'status'
          },
          {
            label: '创建时间',
            type: ColumnType.DATETIME,
            hiddenInForm: true,
            prop: 'gmtCreate'
          },
          {
            label: '修改时间',
            type: ColumnType.DATETIME,
            hiddenInForm: true,
            prop: 'gmtModified'
          }
        ]
      }
    }
  },
  methods: {
    async onAddSuccess(data) {
      await this.$alert('创建账号成功，密码：' + data, '提示')
    },
    handleResetPassword({arg: row}) {
      this.$confirm('确定重置密码吗？', '提示').then(() => {
        adminApi.resetPassword(row.id).then(data => {
          this.$alert('重置密码成功，请使用新密码 => ' + data, '提示')
        })
      })
    }
  }
}
</script>

